import { config } from "dotenv";
config();
import axios from "axios";

export const getUserByEmail = async (email: string) => {
  let serverUrl = process.env.BACK_SERVER_API_URL;
  console.log(`get user by email backserverurl ${serverUrl}`);
  const user = await axios
    .get(`${serverUrl}/user/${email}`)
    .then((response) => {
      return response.data; // The response data
    })
    .catch((error) => {
      console.error("Error fetching data:", error);
    });
  return user;
};

export const getUserById = async (id: string) => {
  let serverUrl = process.env.BACK_SERVER_API_URL;
  console.log(`get user by id backserverurl ${serverUrl}`);

  return fetch(`${serverUrl}/api/user/id/${id}`, { method: "GET" })
    .then((resp) => {
      if (resp.ok) {
        return resp.json();
      }
      return null;
    })
    .catch((err) => {
      console.log(err);
      return null;
    });
};
